Module talk:TableTools
Wikipedia Module:TableTools A similarly named module exists in wikipedia Module:TableTools. Perhaps it would be better to merge this one with the one developed by wikipedians. One benefit is that it is quite robust and has been tested for over 2 years. I'm not sure why it is still in beta though. They probably just forgot to remove the "beta label". Dessamator (talk) 12:39, September 14, 2015 (UTC) Testing I really need to write tests for this module, especially Dev:TableTools.selectFirst(). I'll probably have time to do that tomorrow, but until then, here are some preliminary results: |-|select()= local args = {"one", "two", "three", "four", "five", "six", "seven"} local beyondMax = #args + 2 mw.log("Using `select()`; `args` are as follows:") mw.log(unpack(args)) mw.log() -------------------------------------------------------------------------------- -- (error message) -------------------------------------------------------------------------------- -- mw.log("`n` is 0 with `args` present:") mw.log(select(0, unpack(args))) mw.log() -- -------------------------------------------------------------------------------- -- (error message) -------------------------------------------------------------------------------- -- mw.log("`n` is 0 with `args` missing:") mw.log(select(0)) mw.log() -- -------------------------------------------------------------------------------- -- two three four five six seven -------------------------------------------------------------------------------- mw.log("`n` is 2 with `args` present:") mw.log(select(2, unpack(args))) mw.log() -------------------------------------------------------------------------------- -- (nothing logged, but presumably nil) -------------------------------------------------------------------------------- mw.log("`n` is 2 with `args` missing:") mw.log(select(2)) mw.log() -------------------------------------------------------------------------------- -- (nothing logged, but presumably nil) -------------------------------------------------------------------------------- mw.log("`n` is " .. beyondMax .. " with `args` present:") mw.log(select(beyondMax, unpack(args))) mw.log() -------------------------------------------------------------------------------- -- (nothing logged, but presumably nil) -------------------------------------------------------------------------------- mw.log("`n` is " .. beyondMax .. " with `args` missing:") mw.log(select(beyondMax)) mw.log() -------------------------------------------------------------------------------- -- six seven -------------------------------------------------------------------------------- mw.log("`n` is -2 with `args` present:") mw.log(select(-2, unpack(args))) mw.log() -------------------------------------------------------------------------------- -- (error message) -------------------------------------------------------------------------------- -- mw.log("`n` is -2 with `args` missing:") mw.log(select(-2)) mw.log() -- -------------------------------------------------------------------------------- -- (error message) -------------------------------------------------------------------------------- -- mw.log("`n` is -" .. beyondMax .. " with `args` present:") mw.log(select(-beyondMax, unpack(args))) mw.log() -- -------------------------------------------------------------------------------- -- (error message) -------------------------------------------------------------------------------- -- mw.log("`n` is -" .. beyondMax .. " with `args` missing:") mw.log(select(-beyondMax)) mw.log() -- |-|tableTools.selectFirst()= local selectFirst = require("Dev:TableTools").selectFirst local args = {"one", "two", "three", "four", "five", "six", "seven"} local beyondMax = #args + 2 mw.log("Using `tableTools.selectFirst()`; `args` are as follows:") mw.log(unpack(args)) mw.log() -------------------------------------------------------------------------------- -- one two three four five six seven nil -------------------------------------------------------------------------------- mw.log("`n` is 0 with `args` present:") mw.log(selectFirst(0, unpack(args))) mw.log() -------------------------------------------------------------------------------- -- nil -------------------------------------------------------------------------------- mw.log("`n` is 0 with `args` missing:") mw.log(selectFirst(0)) mw.log() -------------------------------------------------------------------------------- -- one two -------------------------------------------------------------------------------- mw.log("`n` is 2 with `args` present:") mw.log(selectFirst(2, unpack(args))) mw.log() -------------------------------------------------------------------------------- -- nil nil -------------------------------------------------------------------------------- mw.log("`n` is 2 with `args` missing:") mw.log(selectFirst(2)) mw.log() -------------------------------------------------------------------------------- -- one two three four five six seven nil nil -------------------------------------------------------------------------------- mw.log("`n` is " .. beyondMax .. " with `args` present:") mw.log(selectFirst(beyondMax, unpack(args))) mw.log() -------------------------------------------------------------------------------- -- nil nil nil nil nil nil nil nil nil -------------------------------------------------------------------------------- mw.log("`n` is " .. beyondMax .. " with `args` missing:") mw.log(selectFirst(beyondMax)) mw.log() -------------------------------------------------------------------------------- -- one two three four five six -------------------------------------------------------------------------------- mw.log("`n` is -2 with `args` present:") mw.log(selectFirst(-2, unpack(args))) mw.log() -------------------------------------------------------------------------------- -- (stack overflow) -------------------------------------------------------------------------------- -- mw.log("`n` is -2 with `args` missing:") mw.log(selectFirst(-2)) mw.log() -- -------------------------------------------------------------------------------- -- (error message if `beyondMax` max + 1) -- (stack overflow if `beyondMax` > max + 1) -------------------------------------------------------------------------------- -- mw.log("`n` is -" .. beyondMax .. " with `args` present:") mw.log(selectFirst(-beyondMax, unpack(args))) mw.log() -- -------------------------------------------------------------------------------- -- (stack overflow) -------------------------------------------------------------------------------- -- mw.log("`n` is -" .. beyondMax .. " with `args` missing:") mw.log(selectFirst(-beyondMax)) mw.log() -- DarthKitty (talk) 19:57, February 19, 2016 (UTC) :I added some preliminary tests for select(), and reformatted the ones for tableTools.selectFirst() to match. DarthKitty (talk) 18:03, February 20, 2016 (UTC) ::Dev:TableTools.selectFirst() is done! The tests are probably overkill, but they're more-or-less what I used to fix that function... DarthKitty (talk) 00:13, February 22, 2016 (UTC)